package com.wmwx;

import com.myspring.AnnotationConfigApplicationContext;
import com.wmwx.service.OrderService;
import com.wmwx.service.UserService;

public class Test {
    public static void main(String[] args) {
        /*
        // 测试有参构造
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        // 测试 getBean 方法
        UserService userService = (UserService) context.getBean("userService");
        userService.queryAllUsers();
        UserService userService2 = (UserService) context.getBean("userService");
        UserService userService3 = (UserService) context.getBean("userService");
        // 测试单例模式和原型模式
        System.out.println(userService == userService2 && userService2 == userService3);
        // 测试依赖注入
        userService.methodWithOrders();
        // 测试 BeanNameAware
        userService.printBeanName();
        */

        /*
        // 测试循环依赖
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        UserService userService = (UserService) context.getBean("userService");
        OrderService orderService = (OrderService) context.getBean("orderService");
        System.out.println(orderService);
        userService.methodWithOrders();
        System.out.println(userService);
        orderService.methodWithUsers();
        */

        /*
        // 测试 AOP
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        UserService userService = (UserService) context.getBean("userService");
        OrderService orderService = (OrderService) context.getBean("orderService");
        System.out.println(userService.methodWithOrders());
        System.out.println(orderService.methodWithUsers());
        */

        // 测试 AOP 对循环依赖的影响
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        UserService userService = (UserService) context.getBean("userService");
        OrderService orderService = (OrderService) context.getBean("orderService");
        userService.methodWithOrders().methodWithUsers();
        orderService.methodWithUsers().methodWithOrders();
    }
}
